package cn.tedfu.controller;

import cn.tedfu.pojo.Car;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

//MVC里的C层，用来接受请求和作出响应（springMVC）
@RestController//接受请求，并把json数据返回
@RequestMapping("car")  //规定了url地址的写法
public class CarController {
    @RequestMapping("get")
    public Car get(){
        Car c = new Car(10,"法拉利",1000000);
        return c;
    }
    public void set(){
        String url = "http://192.168.1.110:8080/car/get?id=1&name=张三&age=18";
        String[] arr = url.split("\\?");
        arr = arr[1].split("&");
        Map<String,String> map = new ConcurrentHashMap<>();
        for (int i = 0; i <arr.length ; i++) {
            arr = arr[i].split("=");
            map.put(arr[0],arr[1]);
        }
    }
    @RequestMapping("get1")
    //public void get1(int id){//参数是基本类型。访问这个方法必须带参数，否则会报错500；
    public void get1(Integer id,String name){//参数是引用类型，访问这个方法没带参数就是null
        System.out.println(id);
    }
    @RequestMapping("get2")
    public void get2(Car c){//springMVC框架会把请求的参数，封装给car对象
        System.out.println(c.getId()+c.getName()+c.getPrice());
    }
}
